package com.ruoyi.web.controller.app.controller;

import com.ruoyi.framework.web.exception.base.XResult;
import com.ruoyi.sj.domain.WqEweiShopMember;
import com.ruoyi.web.controller.app.intercepter.FilterAnnotation;
import com.ruoyi.web.controller.app.request.RequestRegisterSetPayPasswordEntity;
import com.ruoyi.web.controller.app.service.AppRegisterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @ClassName RegisterController
 * @Description 用户注册
 * @Author tyc@yanyu
 * @Date 2018/12/5 0005 11:14
 **/
@RestController
@RequestMapping("/app/register")
@Api(tags = {"用户注册"})
@SuppressWarnings("ALL")
public class AppRegisterController {
    @Autowired
    private AppRegisterService registerService;

    /**
     * 发送验证码
     *
     * @param mobile
     * @param request
     * @param type
     * @return
     */
    @RequestMapping(value = "sendCode", method = RequestMethod.POST)
    @ApiOperation(value = "发送验证码", position = 1, notes = "发送验证码")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "mobile", value = "手机号码", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "type", value = "类型（0:注册  1:修改密码  2:修改支付密码）", required = true, dataType = "String", paramType = "query")
    })
    public XResult sendCode(String mobile, HttpServletRequest request, String type) {
        Map<String, String> stringStringMap = registerService.sendCode(mobile, request, type);
        return new XResult("发送成功", stringStringMap);
    }

    /**
     * 校验验证码
     *
     * @param request
     * @param mobile
     * @param code
     * @param type
     * @return
     */
    @RequestMapping(value = "VerificationCode", method = RequestMethod.POST)
    @ApiOperation(value = "校验验证码", position = 2, notes = "校验验证码")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "mobile", value = "手机号码", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "type", value = "类型（0:注册  1:修改密码  2:修改支付密码 ）", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "验证码", required = true, dataType = "String", paramType = "query")
    })
    public XResult VerificationCode(HttpServletRequest request, String mobile, String code, String type) {
        return new XResult("验证成功", registerService.verify(request, mobile, code, type));
    }

    /**
     * 新用户注册
     *
     * @param map
     * @return
     */
    @RequestMapping(value = "doRegister", method = RequestMethod.POST)
    @ApiOperation(value = "用户注册，修改密码", position = 3, response = WqEweiShopMember.class, notes = "注册信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "mobile", value = "电话", dataType = "String", paramType = "query", required = true),
            @ApiImplicitParam(name = "pwd", value = "密码 ", dataType = "String", paramType = "query", required = true),
            @ApiImplicitParam(name = "newsPwd", value = "再次输入密码 ", dataType = "String", paramType = "query", required = true),
            @ApiImplicitParam(name = "province", value = "省", dataType = "String", paramType = "query", required = false),
            @ApiImplicitParam(name = "city", value = "市", dataType = "String", paramType = "query", required = false),
            @ApiImplicitParam(name = "area", value = "区", dataType = "String", paramType = "query", required = false),
            @ApiImplicitParam(name = "gender", value = "性别", dataType = "Integer", paramType = "query", required = false),
            @ApiImplicitParam(name = "birthyear", value = "出生年", dataType = "String", paramType = "query", required = false),
            @ApiImplicitParam(name = "birthmonth", value = "出生月", dataType = "String", paramType = "query", required = false),
            @ApiImplicitParam(name = "birthday", value = "出生日", dataType = "String", paramType = "query", required = false),
            @ApiImplicitParam(name = "inviter", value = "邀请人", dataType = "Integer", paramType = "query", required = false),
            @ApiImplicitParam(name = "longitude", value = "经度", dataType = "String", paramType = "query", required = true),
            @ApiImplicitParam(name = "latitude", value = "纬度", dataType = "Integer", paramType = "query", required = true),
            @ApiImplicitParam(name = "type", value = "状态（0、注册 1、找回密码）", required = true, dataType = "Integer", paramType = "query")
    })
    public XResult doRegister(@RequestParam @ApiIgnore Map<String, Object> map) {
        return new XResult("操作成功", registerService.doRegister(map));
    }

    /**
     * APP用户登录
     *
     * @param map
     * @return
     */
    @RequestMapping(value = "login", method = RequestMethod.POST)
    @ApiOperation(value = "APP用户登录", position = 4, notes = "APP用户登录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "mobile", value = "电话", dataType = "String", paramType = "query", required = true),
            @ApiImplicitParam(name = "pwd", value = "密码 ", dataType = "String", paramType = "query", required = true),
            @ApiImplicitParam(name = "longitude", value = "经度", dataType = "String", paramType = "query", required = true),
            @ApiImplicitParam(name = "latitude", value = "纬度 ", dataType = "String", paramType = "query", required = true),
    })
    public XResult login(String mobile, String pwd, String longitude, String latitude) {
        return new XResult("登录成功！", registerService.login(mobile, pwd, longitude, latitude));
    }

    /**
     * 编辑个人资料
     *
     * @param map
     * @return
     */
    @RequestMapping(value = "updateDta", method = RequestMethod.POST)
    @ApiOperation(value = "编辑用户资料", position = 5, notes = "编辑用户资料")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "province", value = "省", dataType = "String", paramType = "query", required = false),
            @ApiImplicitParam(name = "city", value = "市", dataType = "String", paramType = "query", required = false),
            @ApiImplicitParam(name = "area", value = "区", dataType = "String", paramType = "query", required = false),
            @ApiImplicitParam(name = "gender", value = "性别 0、男 1、女  2、性别不明", dataType = "Integer", paramType = "query", required = false),
            @ApiImplicitParam(name = "birthyear", value = "出生年", dataType = "String", paramType = "query", required = false),
            @ApiImplicitParam(name = "birthmonth", value = "出生月", dataType = "String", paramType = "query", required = false),
            @ApiImplicitParam(name = "birthday", value = "出生日", dataType = "String", paramType = "query", required = false),
            @ApiImplicitParam(name = "content", value = "签名", dataType = "text", paramType = "query", required = false),
            @ApiImplicitParam(name = "nickname", value = "昵称", dataType = "String", paramType = "query", required = false),
            @ApiImplicitParam(name = "avatar", value = "头像", dataType = "String", paramType = "query", required = false),
            @ApiImplicitParam(name = "openid", value = "用户ID号", dataType = "String", paramType = "query", required = true),
            @ApiImplicitParam(name = "backgroundPicture", value = "朋友圈背景图片", dataType = "String", paramType = "query", required = false)
    })
    public XResult updateDta(@RequestParam @ApiIgnore Map<String, String> map) {
        return new XResult("修改成功", registerService.updateData(map));
    }

    /**
     * 设置支付密码
     *
     * @param map
     * @return
     */
    @FilterAnnotation(validator = true)
    @PostMapping(value = "setPayPassword")
    @ApiOperation(value = "设置支付密码")
    public XResult setPayPassword(@ApiIgnore HttpServletRequest request, RequestRegisterSetPayPasswordEntity entity) {
        return new XResult("修改成功", registerService.setPayPassword(request, entity));
    }

}
